package com.etcfg.etlaunch.ui;

import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.etcfg.etlaunch.ColorConvertor;

public class PlayerNameCellRender implements TableCellRenderer {

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		JPanel panel = new JPanel();
		panel.setLayout(new FlowLayout(FlowLayout.LEFT));

		String string = (String) value;
		JLabel comp = new JLabel(ColorConvertor.convertToPlainString(string));
		panel.add(comp);

		int height = panel.getPreferredSize().height;
		if (table.getRowHeight() < height) {
			table.setRowHeight(height);
		}
		if (isSelected) {
			panel.setBackground(table.getSelectionBackground());
			comp.setForeground(table.getSelectionForeground());
		} else {
			panel.setBackground(table.getBackground());
			comp.setForeground(table.getForeground());
		}
		return panel;
	}

}
